<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Building Unit List</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
		var buildingUID = "<s:property value='buildingUID' />";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function addNewBuildingUnit() {
  		if(buildingUID==null || buildingUID=="") {
  			Dialog.alert("Please select the building item to be edited！");
  			return;
  		}
  		loadNewModal(path+"beshs/buildingUnitAction!queryBuildingUnitForManage.do?buildingUID="+buildingUID+"&date="+new Date(),"Add a building units","250px","500px");
  	}
  	
  	function updateBuildingUnit(buildingUnitUID) {
  		loadNewModal(path+"beshs/buildingUnitAction!queryBuildingUnitForManage.do?buildingUID="+buildingUID+"&buildingUnitUID="+buildingUnitUID+"&date="+new Date(),"Modify the building units","250px","500px");
  	}
  	
  	function deleteBuildingUnit(buildingUnitUID) {
  		Dialog.confirm("Are you sure to delete this unit?", function() {
  			$.getJSON(path+"beshs/buildingUnitActionJson!deleteBuildingUnitByUID.do?date="+new Date(), {
  				buildingUnitUID: buildingUnitUID
  	  		}, function(data) {
  	  			if(data.success) {
  	  				Dialog.alert("Successful Operation！", function() {
  	  					window.location = path + "beshs/buildingUnitAction!queryUnitByBuildingUID.do?buildingUID="+buildingUID+"&date="+new Date();
  	  				});
  	  			} else {
  	  				Dialog.alert("System error, please contact adminitrator！");
  	  			}
  	  		});
  		});
  	}
  	
  	$(function(){
  		$("input[name='query']").click(function(){
  			var unitName = $("input[name='unitName']").val();
  			window.location = path + "beshs/buildingUnitAction!queryUnitByBuildingUID.do?unitName="+encodeURIComponent(unitName)+"&buildingUID="+buildingUID+"&date="+new Date();
  		});
  		$("input[name='add']").click(function(){
  			addNewBuildingUnit();
  		});
  	});
  </script>
  <body>
  	<div class="content_all">
	  	<!--查询条件-->
	  	<div class="search">
	    	<form><table cellpadding="0" cellspacing="0">
	      		<tr>
	        		<th>Unit：</th>
			        <td><input name="unitName" value="<s:property value='unitName' />" type="text" class="s_input" /></td>
			        <td><input name="query" type="button" value="Query" class="s_btn" />
			        	<s:if test="superManager.contains(#session.user.userID) 
							        || loginUserRoleIDList.contains(sysadmin) 
							        || loginUserRoleIDList.contains(sysShareManager)">
							<input name="add" type="button" value="Add" class="s_btn" />
						</s:if>
	        		</td>
	      		</tr>
	    	</table></form>
	  	</div>
	  	<!--查询列表-->
	  	<div class="search_table_all">
	    	<table class="search_table" cellspacing="0" cellpadding="0">
	      		<thead>
	        		<tr>
		          		<th style="width:50px;">Serial No.</th>
			          	<th>Unit</th>
			          	<th>Operation</th>
	        		</tr>
	      		</thead>
	      		<tbody>
	      			<s:iterator value="buildingUnitList" var="buildingUint" status="status">
	      				<tr>
		          			<td><s:property value="#status.index+1" /></td>
		          			<td><s:property value="#buildingUint.unitName" /></td>
		          			<td>
		          				<s:if test="superManager.contains(#session.user.userID) 
								        || loginUserRoleIDList.contains(sysadmin) 
								        || loginUserRoleIDList.contains(sysShareManager)">
									<a href="javascript:updateBuildingUnit('<s:property value='#buildingUint.id' />')">[Modify]</a>&nbsp;&nbsp;
		          					<a href="javascript:deleteBuildingUnit('<s:property value='#buildingUint.id' />')">[Delete]</a>		
								</s:if>
		          			</td>
		        		</tr>
	      			</s:iterator>
	      		</tbody>
	    	</table>
	  	</div>
	</div>
  </body>
</html>
